Automatic Landscape

Table of Contents

This is a “pair” assignment, which means that if you are working on a team with someone else, you and your partner should do your best to engage in the pair programming model. At any point in time, one of you is “driving,” i.e. actually using the keyboard and mouse. The other is actively engaged following along, preventing bugs, and providing ideas.

You should make sure that over the course of an assignment that you spend roughly the same amount of time each “driving.” I will also ask you to turn in a form rating the work that your partner does. My recommendation is to take turns approximately every 15 minutes or so. Set a timer to help you remember.

1. Overview

One important way to help people understand weather and climate can be to create computer visualizations. Interactive weather maps show clouds and other forms of weather to help people safely make life choices based on weather. Visual simulations of weather changing over long periods of time can be used to help people understand climate dynamics.

For this assignment, you will create an image that can be changed based on conditions provided by the user.

2. Get started

Create a folder in which to store your work for this assignment.

  • If you are working on your own computer, it’s up to you where to put the folder. Your desktop is likely as good a place as any. Make a folder titled landscape.
  • If you are working in the labs in Olin, make sure to first mount the COURSES folder, so that you won’t lose your code when you log out. Once you’ve done so, open up Finder, then navigate to your personal student work folder. You can then make a landscape folder within there.
  • Using your web browser, save this graphics.py file to the folder you created in the step above.
  • Once you’ve done so, you should then open up your new folder in VS Code. To do so, start up VS Code, then drag your folder onto the VS Code window. This should open up the folder within VS Code. If you are asked, click that you trust the authors. You should see the graphics.py file inside it. If you don’t, that means you saved it into the wrong location with your browser, or you’ve opened the wrong folder. Try again, or ask for help before going ahead.

3. Draw a landscape and a cloud

Write Python code to make a canvas of size 500 pixels wide and 700 pixels high, then draw a simple landscape. (By making them odd, it makes the location of the center of the figure a little more clear.) Your landscape doesn’t have to be particularly fancy. For example, you might set the background to blue to represent a sky, then draw a couple of rough hills or buildings using ovals or rectangles.

You’ll be drawing a cloud for this assignment. The central part of your cloud should simply be a circle, and that’s sufficient for this assignment if you want to stop there. But feel free to use multiple overlapping ovals or other techniques around the edges to make your cloud as attractive as you like. I’ll assume for simplicity of explanation in this assignment that your cloud is a circle. If you have extra bumps on it, those should move along with the circle.

4. Make the position of your cloud adjustable

The goal of this part of the assignment is to place the cloud in different places in the sky, depending on where the user of your program wants it. Specifically, your program should ask your user for a wind speed (in miles per hour), and the number of hours that have passed since the center of the cloud first appeared on the left side of the window. Your program should then:

  • draw the cloud in its correct location
  • display the horizontal location where the center of the cloud object should be

Assume that the image is 20 miles across, and that the wind is blowing directly to the right. Here is what the interaction between your program and your user should look like. (The two numbers, i.e. 3.5 and 2.5, are entered in by the user; everything else is displayed by the program.)

Automatic Landscape Builder

What is the windspeed in miles per hour? 3.5
How many hours have passed? 2.5

Here is your picture!
The horizontal coordinate for the center of the circle is 219

You will need to do some arithmetic to determine precisely where the cloud should go:

  • If you divide the number of pixels across by the number of miles across, this will tell you how many pixels are in a mile.
  • If you multiply the wind speed times the number of hours that have passed, this will tell you how many miles the cloud has traveled.
  • If you multiply the number of miles that the cloud has traveled by the number of pixels in a mile, this will tell you the number of pixels in the image that the cloud has traveled.
  • After you have figured out the number of pixels that that the cloud has traveled, you have to round it off to an integer. (A cloud cannot start at half a pixel.) Here is sample code that does rounding:
num1 = 3.2
num2 = round(num1)

This problem can be solved purely with arithmetic: using more advanced programming obscures the fact that there is a straightforward and more efficient approach. Even if you know how to do them, do not use loops, if statements, or other more obscure Python statements that would achieve the same effect.

5. Test your code

Here are some things you can do to test your code:

  • If windspeed = 20 and hours = 0.5, the center of the cloud should appear halfway across the window, and the horizontal coordinate should be 250.
  • If windspeed = 10 and hours = 1, the center of the cloud should appear halfway across the window, and the horizontal coordinate should be 250.
  • If windspeed = 20 and hours = 1, the center of the cloud should be drawn just beyond the visible range, resulting in a horizontal coordinate of 500. This is because the number of pixels the cloud should have moved is exactly equal to the number of pixels across, and so that puts it one pixel to the right of the window.
  • If windspeed = 10 and hours = 1.5, the center of the cloud should appear 3/4 of the way across the screen, and the horizontal coordinate should be 375.
  • If windspeed = -10 and hours = 1, the center of the cloud should be off screen (too far to the left so see) with a horizontal coordinate of -250. The negative windspeed indicates the wind blowing to the left.
  • If windspeed = 10 and hours = -1, the center of the cloud should similarly be off screen with a horizontal coordinate of -250. The negative time indicates that we’re going backwards in time, and asking where it was an hour ago.
  • Here are some more values to try:

    windspeed hours location
    3.5 2.5 219
    0 0 0
    .25 2 12
    -.25 2 -12
    1 1 25
    20 .8 400

6. Style

You should make sure that your program follows good style. You should it as readable as possible for someone else trying to understand them. At a minimum, you should put a brief comment at the top explaining what the program does, and all of your variable names should be meaningful.

7. Grading

You will receive an M for this assignment if…

  • … your program displays the right number indicating where the cloud is, for each of the tests above.
  • … your program is written to work in general, and not to only work for the few specific tests that we have provided.
  • … your approach is not more complex than it needs to be. Specifically, you haven’t done more than 8 arithmetic operations to figure out where the horizontal location should be. (An arithmetic operation is any calculation you do on the numbers, such as addition, rounding off, etc. 8 is more than you need; my solution used 5. We’re only talking about calculations for finding the center of the circle. If you do other calculations because you’ve made an attractive background or to help draw a fancier cloud, that’s fine.)
  • … your picture clearly has a portion of the cloud which is a circle, and the center of that circle appears at the correct location in the window for each of the tests (as far as we can tell by looking at it).
  • … you have used no loops or conditional statements (e.g. for, while, if). [We’ll be doing lots of that later, but the purpose of this assignment is to practice the power of what you can do with pure arithmetic.]

You will receive a grade of E for this assignment if you satisfy the above M requirements, and …

  • … your program has a comment at the top with at least 5 words describing what the program does.
  • … every one of your variable names is meaningful in some way. (Names such as thing, number, etc. are not meaningful.)
  • … your cloud has at least two additional decorative shapes on it, so that your cloud is more realistic to look at.

8. Submit your work

When finished, zip up your code and submit your work through Moodle.

Good luck, and have fun! Remember that lab assistants are available to help out if you need it, and you can attend prefect sessions as well.